home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Resound / ChangeVolumeModule.m < prev    next >
Encoding:
Text File  |  1992-04-03  |  1.3 KB  |  58 lines

  1.  
  2.  
  3. #import "ChangeVolumeModule.h"
  4. #import "Imports.h"
  5.  
  6. @implementation ChangeVolumeModule
  7.  
  8. - CancelChangeVolume:sender
  9. {
  10.     [NXApp stopModal];
  11.     [ChangePanel close];
  12.     return self;
  13. }
  14.  
  15. - ChangeVolume:sender
  16. {
  17.     [NXApp runModalFor: ChangePanel];
  18.     return self;
  19. }
  20.  
  21. - OkayChangeVolume:sender
  22. {
  23.     signed char* TheSoundData8= (signed char*) [[TheModuleController CurrentSound:self] data];
  24.     signed short* TheSoundData16= (signed short int*) TheSoundData8;
  25.     int datalength=[[TheModuleController CurrentSound:self] dataSize];
  26.     int samplingrate=[[TheModuleController CurrentSound:self] samplingRate];
  27.     int x;
  28.     int slider=[PercentChangeField intValue];
  29.     
  30.     [NXApp stopModal];
  31.     
  32.     
  33.     if (samplingrate==SND_RATE_CODEC)
  34.         {
  35.         for(x=1;x<=datalength;x++)
  36.             {
  37.             TheSoundData8[x]=TheSoundData8[x] * slider/100.0;
  38.             if (TheSoundData8 [x] >  127) TheSoundData8 [x] =  127;
  39.             if (TheSoundData8 [x] < -128) TheSoundData8 [x] = -128;
  40.             }
  41.         }
  42.     else
  43.         {
  44.         for(x=1;x<=datalength/2;x++)
  45.             {
  46.             TheSoundData16[x]=TheSoundData16[x]*slider/100;
  47.             if (TheSoundData16 [x] >  32767) TheSoundData16 [x] =  32767;
  48.             if (TheSoundData16 [x] < -32768) TheSoundData16 [x] = -32768;
  49.             }
  50.         }
  51.     [ChangePanel close];
  52.     [TheModuleController SoundChanged: [TheModuleController CurrentSound:self]];
  53.     return self;
  54. }
  55.  
  56.  
  57. @end
  58.